



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class ManagerEmployeesDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public ManagerEmployeesDB()
        {
        }

        public ManagerEmployeesDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<ManagerEmployees> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<ManagerEmployees> lstRet = new List<ManagerEmployees>();

            string strQuery = " select " + strTop  + " * from dbo.[ManagerEmployees]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    ManagerEmployees obj = new ManagerEmployees();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["ManagerID"] != DBNull.Value)
                    {
                        obj.ManagerID = (System.Int64)dr["ManagerID"];
                    }
                    else
                    {
                        obj.ManagerID = -1;
                    } 
 if (dr["EmployeeID"] != DBNull.Value)
                    {
                        obj.EmployeeID = (System.Int64)dr["EmployeeID"];
                    }
                    else
                    {
                        obj.EmployeeID = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<ManagerEmployees> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<ManagerEmployees> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , ManagerEmployees obj)
        {
            
            

                    DbParameter prmManagerID = con.createParameter();
                    prmManagerID.ParameterName = "@ManagerID";
                    prmManagerID.DbType =DbType.Int64;
                    if (obj.ManagerID == null)
                    {
                        prmManagerID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmManagerID.Value = obj.ManagerID;
                    }
                

                    


                    DbParameter prmEmployeeID = con.createParameter();
                    prmEmployeeID.ParameterName = "@EmployeeID";
                    prmEmployeeID.DbType =DbType.Int64;
                    if (obj.EmployeeID == null)
                    {
                        prmEmployeeID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmEmployeeID.Value = obj.EmployeeID;
                    }
                

                    


           



            string strQuery = " insert into dbo.[ManagerEmployees] ([ManagerID],[EmployeeID]) VALUES (@ManagerID,@EmployeeID) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmManagerID,prmEmployeeID);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(ManagerEmployees obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, ManagerEmployees obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmManagerID = con.createParameter();
                    prmManagerID.ParameterName = "@ManagerID";
                    prmManagerID.DbType =DbType.Int64;
                    if (obj.ManagerID == null)
                    {
                        prmManagerID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmManagerID.Value = obj.ManagerID;
                    }
                

                    


                    DbParameter prmEmployeeID = con.createParameter();
                    prmEmployeeID.ParameterName = "@EmployeeID";
                    prmEmployeeID.DbType =DbType.Int64;
                    if (obj.EmployeeID == null)
                    {
                        prmEmployeeID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmEmployeeID.Value = obj.EmployeeID;
                    }
                

                    


           



            string strQuery = " update dbo.[ManagerEmployees] set [ManagerID]=@ManagerID,[EmployeeID]=@EmployeeID where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmManagerID,prmEmployeeID);

            

        }


        public void Update(ManagerEmployees obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, ManagerEmployees obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[ManagerEmployees]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( ManagerEmployees obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<ManagerEmployees> getManagerEmployeesByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<ManagerEmployees> lstRet = new List<ManagerEmployees>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<ManagerEmployees> getManagerEmployeesByID(System.Int64 ID)
                    {
                        List<ManagerEmployees> lstRet = new List<ManagerEmployees>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getManagerEmployeesByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<ManagerEmployees> getManagerEmployeesByManagerID(ClassDataHandler con,System.Int64 ManagerID)
                    {
                        List<ManagerEmployees> lstRet = new List<ManagerEmployees>();


                        DbParameter prmManagerID = con.createParameter();
                        prmManagerID.ParameterName = "@ManagerID";
                        prmManagerID.DbType = DbType.Int64;
                        if (ManagerID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmManagerID.Value = ManagerID;
                        }


                        lstRet = Select(con, "" , " where [ManagerID]=@ManagerID ", prmManagerID);



                        return lstRet;

                    }


                    public List<ManagerEmployees> getManagerEmployeesByManagerID(System.Int64 ManagerID)
                    {
                        List<ManagerEmployees> lstRet = new List<ManagerEmployees>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getManagerEmployeesByManagerID(con, ManagerID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<ManagerEmployees> getManagerEmployeesByEmployeeID(ClassDataHandler con,System.Int64 EmployeeID)
                    {
                        List<ManagerEmployees> lstRet = new List<ManagerEmployees>();


                        DbParameter prmEmployeeID = con.createParameter();
                        prmEmployeeID.ParameterName = "@EmployeeID";
                        prmEmployeeID.DbType = DbType.Int64;
                        if (EmployeeID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmEmployeeID.Value = EmployeeID;
                        }


                        lstRet = Select(con, "" , " where [EmployeeID]=@EmployeeID ", prmEmployeeID);



                        return lstRet;

                    }


                    public List<ManagerEmployees> getManagerEmployeesByEmployeeID(System.Int64 EmployeeID)
                    {
                        List<ManagerEmployees> lstRet = new List<ManagerEmployees>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getManagerEmployeesByEmployeeID(con, EmployeeID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<ManagerEmployees> Search(ClassDataHandler con, ManagerEmployees obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.ManagerID != -1)
                    {
                        DbParameter prmManagerID = con.createParameter();
                        prmManagerID.ParameterName = "@ManagerID";
                        prmManagerID.DbType =DbType.Int64;
                        if (obj.ManagerID == null)
                        {
                            prmManagerID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmManagerID.Value = obj.ManagerID;
                        }
                        strWhere += " [ManagerID]=@ManagerID AND ";
                        lstParameters.Add(prmManagerID);
                     }



                    

                    if (obj.EmployeeID != -1)
                    {
                        DbParameter prmEmployeeID = con.createParameter();
                        prmEmployeeID.ParameterName = "@EmployeeID";
                        prmEmployeeID.DbType =DbType.Int64;
                        if (obj.EmployeeID == null)
                        {
                            prmEmployeeID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmEmployeeID.Value = obj.EmployeeID;
                        }
                        strWhere += " [EmployeeID]=@EmployeeID AND ";
                        lstParameters.Add(prmEmployeeID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<ManagerEmployees> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<ManagerEmployees> Search(ManagerEmployees obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<ManagerEmployees> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<ManagerEmployees> SearchOrLike(ClassDataHandler con, ManagerEmployees obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.ManagerID != -1)
                    {
                        DbParameter prmManagerID = con.createParameter();
                        prmManagerID.ParameterName = "@ManagerID";
                        prmManagerID.DbType =DbType.Int64;
                        if (obj.ManagerID == null)
                        {
                            prmManagerID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmManagerID.Value = obj.ManagerID;
                        }
                        strWhere += " [ManagerID]=@ManagerID OR ";
                        lstParameters.Add(prmManagerID);
                     }



                    

                    if (obj.EmployeeID != -1)
                    {
                        DbParameter prmEmployeeID = con.createParameter();
                        prmEmployeeID.ParameterName = "@EmployeeID";
                        prmEmployeeID.DbType =DbType.Int64;
                        if (obj.EmployeeID == null)
                        {
                            prmEmployeeID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmEmployeeID.Value = obj.EmployeeID;
                        }
                        strWhere += " [EmployeeID]=@EmployeeID OR ";
                        lstParameters.Add(prmEmployeeID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<ManagerEmployees> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<ManagerEmployees> SearchOrLike(ManagerEmployees obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<ManagerEmployees> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            